local BasePlugin = require "kong.plugins.base_plugin"
local access = require "kong.plugins.oss-simple.access"
local string_find = string.find

local OssSimple = BasePlugin:extend()

OssSimple.VERSION  = "1.0.0"
OssSimple.PRIORITY = 1007

function OssSimple:new()
  OssSimple.super.new(self, "oss-simple")
end

function OssSimple:access(config)
  OssSimple.super.access(self)
  local subfix_pattern = config.subfix_pattern
  local from = string_find(kong.request.get_path(), subfix_pattern, nil, false)
  if from then
    kong.log.inspect(config)
    access.execute(config)
    local main_url = config.main_url
    kong.response.exit(301,"Redirect to https",{["Location"] = main_url });
  end
end

return OssSimple
